import ReactDom from "react-dom/client"
import Loading from "./loading"

let count = 0
export const showLoading = () => {
  if (count === 0) {
    const loading = document.getElementById("loading")
    if (loading) {
      loading.style.setProperty("display", "flex")
      ReactDom.createRoot(loading).render(<Loading />)
    }
  }
  count++
}

export const hideLoading = () => {
  if (count <= 0) {
    count = 0
    return
  }
  count--
  if (count === 0)
    document.getElementById("loading")?.style.setProperty("display", "none")
}
